package com.hnas.trade.service.mapper;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.hnas.core.mapper.Mapper;
import com.hnas.core.util.StringUtil;
import com.hnas.trade.domain.DetailType;
import com.hnas.trade.orm.OrderDetail;
import com.hnas.trade.service.dto.DTOOrderDetail;
import com.hnas.trade.service.dto.DTOTradeRecord;

public class OrderDetailMapper extends Mapper<DTOOrderDetail, OrderDetail>{
	private static OrderDetailMapper mapper;
	private OrderDetailMapper(){
		super(DTOOrderDetail.class,OrderDetail.class);
	}
	public static OrderDetailMapper getInstance(){
		if(mapper == null){
			mapper = new OrderDetailMapper();
		}
		return mapper;
	}
	public DTOOrderDetail mapToValue(OrderDetail vo){
		if(vo == null) return null;
		DTOOrderDetail dto = new DTOOrderDetail();
		BeanUtils.copyProperties(vo, dto);
		if(StringUtil.isNotEmpty(dto.getType())){
			dto.setTypeStr(DetailType.getDetailTypeValue(dto.getType()));
		}
		// TODO discountTypeName
//		if(StringUtil.isNotEmpty(dto.getType())){
//			dto.setTypeStr(DetailType.getDetailTypeValue(dto.getType()));
//		}
		return dto;
	}
	public List<DTOOrderDetail> mapToValue(List<OrderDetail> list){
		if(list == null) return null;
		List<DTOOrderDetail> dtoList = new ArrayList<DTOOrderDetail>();
		for(OrderDetail vo : list){
			dtoList.add(mapToValue(vo));
		}
		return dtoList;
	}
	
	public DTOTradeRecord mapToDTOTradeRecord(OrderDetail vo){
		if(vo == null) return null;
		DTOTradeRecord dto = new DTOTradeRecord();
		BeanUtils.copyProperties(vo, dto);
		return dto;
	}
	
}
